#include "defines.h"
#include "system.h"
#include "display.h"
#include "image.h"
#include "cal.h"
#include "GT22.h"
#include "packet_handl.h" 
#include "CC2500.h"
#include "led.h" 
#include "rtc.h"
#include "hal_ucs.h"
#include "flashUtils.h"

void main()
{  
	volatile unsigned int i = 0;
    volatile unsigned int j = 0;   
//    Calendar currentTime;
    
	// System Initialization
	StopWatchdog();               // Stop watchdog timer.
//	ConfigPorts();                // Configure I/O ports.
	
    P5SEL |= BIT4 + BIT5;                       // Port select XT1
 
	//Initialize clock and peripherals
//    halBoardInit();
//	LFXT_Start(XT1DRIVE_3, XCAP_3);
//    Init_FLL_Settle(8000, 244);

//	LED_config();
//    LED1_set();

	setupRTC();

	__bis_SR_register(LPM3_bits + GIE); // Enter LPM3
}

#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR (void)
{
    switch (__even_in_range(RTCIV,16)){
        case 0: break;  //No interrupts
        case 2:         //RTCRDYIFG
            //Toggle P1.0 every second
//			LED1_toggle();
            break;
        case 4:         //RTCEVIFG
            //Interrupts every minute
            
            //Read out New Time a Minute Later BREAKPOINT HERE 
//			if (++active_time_count == 2) {
//				active_time_count = 0;
//				CpuMode = LPM3_MODE;
//			}

			__bic_SR_register_on_exit(LPM3_bits);
            
            break;
        case 6:         //RTCAIFG
			__bic_SR_register_on_exit(LPM3_bits);
			
            break;
        case 8: break;  //RT0PSIFG
        case 10: break; //RT1PSIFG
        case 12: break; //Reserved
        case 14: break; //Reserved
        case 16: break; //Reserved
        default: break;
    }
}

